#ifndef IMSI_SCOPEDHANDLE_H
#define IMSI_SCOPEDHANDLE_H

class ScopedHandle
{
private:
    mutable HANDLE Item;

public:
    ScopedHandle (HANDLE aItem)
        : Item (aItem)
    {  }

    ScopedHandle (const ScopedHandle& aOther)
    {
        Item = aOther.Item;
        aOther.Item = INVALID_HANDLE_VALUE;
    }

    const ScopedHandle& operator= (const ScopedHandle& aOther)
    {
        Item = aOther.Item;
        aOther.Item = INVALID_HANDLE_VALUE;

        return *this;
    }

    ~ScopedHandle ()
    {
        if (Item != INVALID_HANDLE_VALUE) {
            CloseHandle (Item);
        }
        Item = INVALID_HANDLE_VALUE;
    }

    HANDLE operator() () const
    {
        return Item;
    }
};

#endif // IMSI_SCOPEDHANDLE_H
